﻿<?php

 include ('style/top.php');
 include ('style/menu.php');
 include ('style/left.php');
 ?>
 
 <div class="content">
    <div id="contentop">
        <div class="logohinhtop"></div>
        <div class="khungchutop">
       	    <div id="chu">Trang chủ <img src="images/arrow.png" /> Tin tức</div>
        </div>   
    </div>
    <div class ="khungtintuc">
    <?php
     $xemtintuc =  $_GET['viewtintucid'];
    if(isset($xemtintuc ) == ''){
  //phân trang 
    
    $sql = "SELECT COUNT(id) FROM tintuc  ";
    $ketqua = mysql_query($sql) or die("die rồi".mysql_error());
    $num = mysql_fetch_row($ketqua);
   // echo "<pre>" ; print_r($num);
    $resul_num = $num[0];
    // đặt số dòng hiển thị
    $row_hienthi = 9;
    
    //tính số trang hiển thị
    $num_page = ceil($resul_num/$row_hienthi);
    
    
    $page = isset($_GET['page'])?$_GET['page']:1;
    if($page > $num_page)  $page = $num_page;
    
    if($page < 1) $page = 1;
  
    // vị trí bắt đầu hiển thị bản ghi
    $start = ($page - 1)* $row_hienthi;
   
    
  //end phân trang
    $query = "SELECT * FROM tintuc WHERE hien_thi ='0' ORDER BY id DESC LIMIT $start , $row_hienthi";
    $resul = mysql_query($query) or die ("không kết nối được".mysql_error());
    while ($row = mysql_fetch_array($resul)){
         $str =   $row['noidung'];
         $id_tin = $row['id'];
        echo "  <table width=\"600\" border=\"0\">\n"; 
        echo "    <tr>\n"; 
        echo " <div class = 'baonoidungtintuc' >";
            echo "<div class = 'divhienthi'>";
                echo "<div class = 'imghienthi'><a href ='tintuc.php?viewtintucid= ".$row['id']."'><img src='".get_first_img_tintuc($id_tin)."' width='120' height='120' /></a></div>";
                echo " <h4 class = 'noidungtieude' ><a href ='tintuc.php?viewtintucid= ".$row['id']."'>".$row['tieude']."</a></h4>";
                echo "<div class = 'ndhienthi'>".dots_string($str,200)."</div>"; 
            echo "</div>";
        echo "</div>";     
        echo "    </tr>\n"; 
        echo "  </table>\n";
     }
     // xử lý phân trang
    echo "<div class ='phantrang'>"; 
        echo "<ul>";
            echo "<li class ='fonttrang'> Trang : ";
                for($i =1;$i<=$num_page;$i++){
        		if($page!=$i){
        			echo "<a class ='sotrang' href='?page=$i' title ='Trang $i'>$i</a>"; 
        		}
        		else{
  	                 echo "<a class ='tranghienthi'>$i</a>";
    		      }	
        
        	   }
            echo "</li>";
        echo "</ul>";
    echo "</div>"; 
     
    // neu truong hop xem het cua tin tuc thi se chay doan nay  
   }else{
    $query = "SELECT * FROM tintuc WHERE id = ".$xemtintuc ;
    $resul = mysql_query($query);
    while ($row = mysql_fetch_array($resul)){
        
        echo "  <table width=\"600\" border=\"0\">\n"; 
        echo "    <tr>\n"; 
        echo " <h4 class = 'ndtieudetin' >".$row['tieude']."</h4>";
        echo "</h4>";
        echo "    </tr>\n"; 
        echo "    <tr>\n"; 
        echo " <div class = 'baonoidungtintuc' >";
        echo                 $row['noidung'];
        echo "</div>";
        echo      "</td>"; 
        echo "    </tr>\n";
        echo "  </table>\n";
    
   }    
        // các tin liên quan 
        echo "<div class= 'tinlienquan'>";
            echo "<span class='titletinlienquan'> Các tin tức khác :</span> ";
            $sl = "SELECT * FROM tintuc WHERE id != ".$xemtintuc." LIMIT 0, 6  ";
            $ketqua = mysql_query($sl);
            while ($banghi = mysql_fetch_array($ketqua)){
                echo "  <ul>";
                    echo " <li><a href='tintuc.php?viewtintucid=".$banghi['id']."'> ".$banghi['tieude']." </a></li>";
                echo "</ul> ";
         } 
        echo "</div>";   

 } 
   
 ?>
  </div>
  </div>
  <?php
 include ('style/right.php');
 include ('style/bottom.php');
?>